$(function () {
    initMap();
});

function initMap() {
    var param = {};
    param.areaName = "陕西";
    map = MapUtil.createMap("map", {}, param);
}

function clearAreaInfo() {
    MapUtil.clearAll(map);
    $(".area-info").hide();
}

function toggleAreaInfo() {
    var $body = $(".panel-body");
    if ($body.is(":hidden")) {
        $body.slideDown();
        $(".btn-toggle").text("折叠面板");
    } else {
        $body.slideUp();
        $(".btn-toggle").text("展开面板");
    }
}

function gpsDemo() {
    var gisstr = "109.02408, 34.112316;\n108.948191,34.119967;\n108.863103,34.181151;\n108.771117,34.177328;\n108.667632,34.05491";
    $("#gpsTextarea").val(gisstr);
}

function showGps() {
    var points = $("#gpsTextarea").val();
    points = $.trim(points);
    if (points.length < 1) {
        return;
    }
    var pointsArr = points.split(';');
    if (pointsArr.length < 1) {
        return;
    }
    var pArr = [];
    for (var i = 0; i < pointsArr.length; i++) {
        var lngLatLabel = pointsArr[i].split(',');
        var lng = lngLatLabel[0];
        var lat = lngLatLabel[1];
        pArr.push({
            "lng": lng,
            "lat": lat
        })
    }
    MapUtil.createPoints(pArr);
}

function showBd() {
    var points = $("#bdTextarea").val();
    points = $.trim(points);
    if (points.length < 1) {
        return;
    }
    var pointsArr = points.split(';');
    var pArr = [];
    for (var i = 0; i < pointsArr.length; i++) {
        var lngLatLabel = pointsArr[i].split(',');
        var lng = lngLatLabel[0];
        var lat = lngLatLabel[1];
        pArr.push({
            "lng": lng,
            "lat": lat
        })
    }
    var markerOption = {
        icon: new BMap.Symbol(BMap_Symbol_SHAPE_STAR, {
            scale: 1,
            fillColor: 'blue',
            fillOpacity: 0.8,
            strokeColor: 'blue',
            strokeOpacity: 0.8
        })
    };
    MapUtil.createPoints(pArr, markerOption);
}

function gpsToBaidu() {
    try {
        var points = $("#gpsTextarea").val();
        MapUtil.gpsToBaidu(points, function (arr) {
            $("#bdTextarea").val(arr.join(";\n"));
        });
    } catch (e) {
        console.error(e);
    }
}